﻿using System.ComponentModel;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;

namespace BootstrapBlazorApp.Server.Utils;

public class Md5Utils
{
    public static string Md5Encrypt32(string password)
    {
        var md5 = MD5.Create(); //实例化一个md5对像
        // 加密后是一个字节类型的数组，这里要注意编码UTF8/Unicode等的选择　
        byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
        // 通过使用循环，将字节类型的数组转换为字符串，此字符串是常规字符格式化所得
        return s.Aggregate("", (current, t) => current + t.ToString("X"));
    }
    
    public static Dictionary<string, string> GetEnumDic(Type enumType)
    {
        Dictionary<string, string> dic =new Dictionary<string, string>();
        FieldInfo[] fieldinfos = enumType.GetFields();
        foreach (FieldInfo field in fieldinfos)
        {
            if (field.FieldType.IsEnum)
            {
                Object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);

                dic.Add(field.Name, ((DescriptionAttribute)objs[0]).Description);
            }

        }

        return dic;
    }
}